<template>
  <div class="privilege">
    <!-- 按钮 -->
    <div class="btns">
      <el-button size="big" type="info" @click="toAdd">添加</el-button>
  <el-dropdown>
  <el-button type="danger" >
    返回<i class="el-icon-arrow-down el-icon--right"></i>
  </el-button>
  <el-badge :value="1" class="item" >
    <el-button size="mini" width=100>建议</el-button>
</el-badge>
<el-badge :value="0" class="item">
  <el-button size="mini">反馈</el-button>
</el-badge>
<el-dropdown trigger="click">
  <span class="el-dropdown-link">
    点我查看<i class="el-icon-caret-bottom el-icon--right"></i>
  </span>
  <el-dropdown-menu slot="dropdown">
    <el-dropdown-item class="clearfix">
      评论
      <el-badge class="mark" :value="12" />
    </el-dropdown-item>
    <el-dropdown-item class="clearfix">
      回复
      <el-badge class="mark" :value="3" />
    </el-dropdown-item>
  </el-dropdown-menu>
</el-dropdown>
  <el-dropdown-menu slot="dropdown">
    <el-dropdown-item>用户管理</el-dropdown-item>
    <el-dropdown-item>文章管理</el-dropdown-item>
    <el-dropdown-item>种类管理</el-dropdown-item>
    <el-dropdown-item>评论管理</el-dropdown-item>
    <el-dropdown-item>日志管理</el-dropdown-item>
    <el-dropdown-item>消息管理</el-dropdown-item>
    <el-dropdown-item>纪市管理</el-dropdown-item>
    <el-dropdown-item>角色管理</el-dropdown-item>
    <el-dropdown-item>角色权限管理</el-dropdown-item>
  </el-dropdown-menu>
</el-dropdown>
    </div>
    <!-- 表格 -->
    <el-table :data="list" style="width: 100%" size="small">
      <el-table-column type="index" label="序号"> </el-table-column>
      <el-table-column prop="name" label="名称" width="180"> </el-table-column>
      <el-table-column prop="icon" label="图标"> </el-table-column>
      <el-table-column prop="type" label="类型"> </el-table-column>
      <el-table-column prop="path" label="路径"> </el-table-column>  
      <el-table-column prop="is_hidden" label="隐藏"> </el-table-column>
      <el-table-column prop="introduce" label="介绍"> </el-table-column>
       <el-table-column prop="long" label="个人ID"> </el-table-column>
      <el-table-column label="操作" width="150" align="center"> 
        <template v-slot="scope">
        <el-button size="small" type="danger" @click="del(scope.row)">删除</el-button>
          <el-button size="small" type="primary" @click="edit(scope.row)">修改</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 模态框 -->
    <el-dialog
      class="customer_modal"
      title="添加信息"
      :visible.sync="dialogVisible"
      width="60%">
      {{form}}
       <el-form :model="form" label-width="100px">
        <el-form-item label="名称" >
          <el-input v-model="form.name"></el-input>
       </el-form-item>
         </el-form>
        <el-form :model="form" label-width="100px">
          <el-form-item label="图标" >
           <el-input v-model="form.icon"></el-input>
        </el-form-item>
         </el-form>
        <el-form :model="form" label-width="100px">
          <el-form-item label="类型" >
           <el-input v-model="form.type"></el-input>
        </el-form-item>
         </el-form>
        <el-form :model="form" label-width="100px">
          <el-form-item label="路径" >
           <el-input v-model="form.path"></el-input>
        </el-form-item>
         </el-form>
        <el-form :model="form" label-width="100px">
          <el-form-item label="隐藏" >
           <el-input v-model="form.is_hidden"></el-input>
        </el-form-item>
         </el-form>
        <el-form :model="form" label-width="100px">
          <el-form-item label="介绍" >
            <el-input v-model="form.introduce"></el-input>
        </el-form-item>
         </el-form>
        <el-form :model="form" label-width="100px">
          <el-form-item label="个人ID" >
           <el-input v-model="form.long"></el-input>
        </el-form-item>
         </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false" size="small">取 消</el-button>
        <el-button type="primary" @click="save" size="small">确 定</el-button>
      </span>
    </el-dialog>
    </div>
</template>
<script>
// 导入request , 浏览器提供给我们的用于与后台进行交互的工具 api
import {get,post} from '@/utils/request'
export default {
  data (){
    return {
      form:{},
      list:[],
      dialogVisible:false
    }
  },
  created(){
    this.loadData();
  },
  methods:{
    // 保存
    save(){
      let url = "/privilege/saveOrUpdate"
      post(url,this.form).then( (response)=>{
        // 1. 模态框关闭
        this.dialogVisible = false;
        // 2. 提示
        this.$message({type:"success",message:response.message})
        // 3. 刷新
        this.loadData();
      } )
    },
    // 删除
    del(row){
      let url = "/privilege/deleteById"
      get(url,{id:row.id}).then( (response)=>{
        // 1. 提示
        this.$message({type:"success",message:response.message})
        // 2. 刷新 
        this.loadData();
      } )
    },
    // 编辑
    edit(row){
      this.form = row;
      this.dialogVisible = true;
    },
    // 加载数据
    loadData(){
      let url = "/privilege/findAll";
      get(url).then( (response)=>{
        // response就是后端返回给我们的Message{status,message,data,timestamp}
        this.list = response.data;
      } );
    },
    toAdd(){
      this.dialogVisible = true;
    }
  }
}
</script>